﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HomeAutomation.actions
{
    class DeviceAction : Action
    {
        public Device device { get; set; }
        public Command command { get; set; }

        public DeviceAction(Device device, Command command)
        {
            this.device = device;
            this.command = command;
        }

        public void fire()
        {
            //Form1.plm;

            //DeviceBase device;
            //if (plm.Network.TryConnectToDevice(location, out device))
            //{
            //    var lightingControl = device as DimmableLightingControl;

            //    switch (c)
            //    {
            //        case Command.On:
            //            lightingControl.TurnOn();
            //            break;
            //        case Command.Off:
            //            lightingControl.TurnOff();
            //            break;
            //        default:
            //            log("Don't know what to do with " + c + " in " + location);
            //            return false;
            //    }
            //    return true;
            //}
        }


        public override bool Equals(System.Object obj)
        {

            if (obj != null && obj is DeviceAction)
            {
                DeviceAction deviceAction = (DeviceAction)obj;

                bool devicesEqual = false;
                if (device == null && deviceAction.device == null)
                {
                    devicesEqual = true;
                }
                else if (device != null)
                {
                    devicesEqual = device.Equals(deviceAction.device);
                }

                bool commandsEqual = false;

                if (command == null && deviceAction.command == null)
                {
                    commandsEqual = true;
                }
                else if (command != null)
                {
                    commandsEqual = command.Equals(deviceAction.command);
                }

                return devicesEqual == true && commandsEqual == true;

            }

            return false;
        }

        public override int GetHashCode()
        {
            int hash = 23;
            hash = hash * 29 + (device != null ? device.GetHashCode() : 0);
            hash = hash * 29 + (command != null ? command.GetHashCode() : 0);
            return hash;
        }
    }
}
